/**
 * 
 */
package com.hefei.blog.base.utils;

import java.io.File;
import java.util.Date;

import org.apache.commons.lang.time.DateFormatUtils;
import org.apache.log4j.Logger;

public class FilePathUtils {
	
	private static Logger log = Logger.getLogger(FilePathUtils.class);
	
	private static final String YYYYMMDD = "yyyy/MM/dd/";
	
	public static String getAvatarPath() {
		return DateFormatUtils.format(new Date(), YYYYMMDD);
	}
	public static String getPicPath() {
		return DateFormatUtils.format(new Date(), YYYYMMDD);
	}
	
	public static String getHtmlPath(){
		return DateFormatUtils.format(new Date(), YYYYMMDD);
	}
	
	public static void checkDirAndCreate(File file) {
		if (!file.getParentFile().exists()) {
			file.getParentFile().mkdirs();
		}
	}
	
	public static void deleteRelativeFile(String root, String relativePath) {
		File file = new File(root + relativePath);

		// 文件存在, 且不是目录
		if (file.exists() && !file.isDirectory()) {
			file.delete();
			log.info("fileRepo delete " + relativePath);
		}
	}
	
	public static void main(String[] args) {
		String base = FilePathUtils.getAvatarPath();
		System.out.println(base);
	}
	
}
